﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace IGolovkine.Core.Diagnostics
{
    public static class ObjectDumper
    {
        public static string Format(object source)
        {
            Debug.NotDefault(() => source);
            StringBuilder buffer = new StringBuilder();
            buffer.AppendFormat("{0}: ", source.GetType().Name);
            buffer.Append("{");

            PropertyInfo[] properties = source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (var property in properties)
            {
                if (property.Name != "Item")
                {
                    buffer.AppendFormat("{0} = {1}", property.Name, property.GetValue(source, null));
                    if (property != properties.LastOrDefault())
                    {
                        buffer.Append(", ");
                    }
                }
            }
            buffer.Append("}");
            return buffer.ToString();
        }
    }
}
